package com.itheima.controller;

import com.itheima.entity.BookMessageConstant;
import com.itheima.entity.CodeConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Game;
import com.itheima.service.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ChaunceyZhang
 * @date 2022-10-21 21:11
 * @blog1 https://zephyr-cyber.github.io/
 * @blog2 https://www.yuque.com/gougougou-xwscx
 */
@RestController
@RequestMapping("/game")
public class GameController {
    @Autowired
    private GameService gameService;

    @GetMapping
    public Result findAll(){
        List<Game> gameServiceAll = gameService.findAll();
        return Result.success(CodeConstant.GET_OK, BookMessageConstant.BOOK_QUERY_OK,gameServiceAll);
    }

    @PostMapping
    public Result save(@RequestBody Game game){
        Boolean save = gameService.save(game);
        return Result.success(CodeConstant.SAVE_OK,BookMessageConstant.BOOK_SAVE_OK,null);
    }

    @PutMapping
    public Result update(@RequestBody Game game) {
        Boolean update = gameService.update(game);
        return  Result.success(CodeConstant.UPDATE_OK,BookMessageConstant.BOOK_UPDATE_OK,null);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id){
        Boolean delete = gameService.delete(id);
        return  Result.success(CodeConstant.DELETE_OK,BookMessageConstant.BOOK_DELETE_OK,null);

    }

}
